package com.sheledon.flyCat.network.socket.http;

import com.sheledon.flyCat.network.socket.http.enum_.HttpStatus;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;

/**
 * @author sheledon
 */
@Data
public class HttpResponse implements Serializable {
    private String version="HTTP/1.1";
    private HttpStatus status;
    private HashMap<String,String> responseHeaders;
    private Object body;
    private String transferHeaders(){
        if (responseHeaders==null){
            return "";
        }
        StringBuilder builder = new StringBuilder();
        responseHeaders.forEach((key,value)->{
            builder.append(key).append(":").append(value).append("\r\n");
        });
        return builder.toString();
    }
    public String transferResponse(){
        String str = version+" "+status+"\r\n" +
                transferHeaders()+"\r\n" +
                "\r\n" ;
        return body==null ? str : str+body;
    }
}
